package com.kymatrix.kycarbon.xsmd.system.server.outer;

import cn.hutool.core.collection.CollUtil;
import com.kymatrix.kycarbon.xsmd.system.server.model.entity.UserRoleRelationEntity;
import com.kymatrix.kycarbon.xsmd.system.api.service.PermissionApi;
import com.kymatrix.kycarbon.xsmd.system.server.dao.UserRoleMapper;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author liujie
 * @date 2024-04-22
 */
@Service
@Slf4j
public class PermissionApiImpl implements PermissionApi {
    
    @Resource 
    private UserRoleMapper userRoleMapper;
    
    @Override
    public Set<String> getUserRoleIdListByRoleIds(Collection<String> roleIds) {
        if (CollUtil.isEmpty(roleIds)) {
            return Collections.emptySet();
        }
        List<UserRoleRelationEntity> list = userRoleMapper.selectByRoleIds(roleIds);
        return list.stream().map(UserRoleRelationEntity::getUserId).collect(Collectors.toSet());
    }

    @Override
    public boolean hasAnyPermissions(Long userId, String... permissions) {
        return false;
    }

    @Override
    public boolean hasAnyRoles(Long userId, String... roles) {
        return false;
    }
}
